package org.example.evaluate.enums;

import java.math.BigDecimal;
import java.util.stream.Stream;

public enum Appearance {
    quan_xin_one(42, "全新(原封未拆/未使用（需提供身份证及购机发票，无法提供不回收）)", BigDecimal.valueOf(1)),
    jiu_wu_one(43, "95新(外观完好无磕碰/掉漆/划痕)", BigDecimal.valueOf(0.9)),
    ba_jiu_one(44, "8-9新(机身有明显划痕)", BigDecimal.valueOf(0.8)),
    liu_qi_one(45, "6-7新(机身有磕碰/破裂/掉漆及屏幕与机身分离情况)", BigDecimal.valueOf(0.6)),
    quan_xin(82, "全新", BigDecimal.valueOf(1)),
    jiu_jiu(83, "9.9新", BigDecimal.valueOf(0.9)),
    jiu_wu(84, "9.5成新", BigDecimal.valueOf(0.85)),
    ba_jiu(85, "8-9成新", BigDecimal.valueOf(0.8)),
    liu_qi(86, "6-7新", BigDecimal.valueOf(0.7)),
    wu(87, "5成新", BigDecimal.valueOf(0.6));

    private final Integer code;
    private final String name;
    private final BigDecimal kf;

    Appearance(Integer code, String name, BigDecimal kf) {
        this.code = code;
        this.name = name;
        this.kf = kf;
    }

    public Integer getCode() {
        return code;
    }

    public BigDecimal getKf() {
        return kf;
    }

    public static Appearance buildAppearance(Integer code) {
        return Stream.of(Appearance.values())
                .filter(v -> v.getCode() == code)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException(String.format("传入的外观码 [%s] 不正确", code)));
    }
}
